
package com.yjh.admin.controller.chronic;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yjh.admin.entity.chronic.Reference;
import com.yjh.admin.server.chronic.ReferenceService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import util.R;


/**
 * 体征参考
 *
 * @author GuoBin
 * @date 2020-08-14 16:51:45
 */
@ApiOperation("体征参考")
@RestController
@AllArgsConstructor
@RequestMapping("/reference")
public class ReferenceController {

    private final ReferenceService referenceService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param reference 体征参考
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public R getReferencePage(Page page, Reference reference) {
        return  new R<>(referenceService.page(page,Wrappers.query(reference)));
    }


    /**
     * id查询体征参考
     * @param referenceId id
     * @return R
     */
    @ApiOperation("通过id查询体征参考")
    @GetMapping("/getById")
    public R getById(@RequestParam("referenceId") Integer referenceId){
        return new R<>(referenceService.getById(referenceId));
    }

    /**
     * 新增体征参考
     * @param reference 体征参考
     * @return R
     */
    @ApiOperation("新增体征参考")
    @PostMapping
    public R save(@RequestBody Reference reference){
        return new R<>(referenceService.save(reference));
    }

    /**
     * 修改体征参考
     * @param reference 体征参考
     * @return R
     */
    @ApiOperation("修改体征参考")
    @PutMapping
    public R updateById(@RequestBody Reference reference){
        return new R<>(referenceService.updateById(reference));
    }

    /**
     * 通过id删除体征参考
     * @param referenceId id
     * @return R
     */
    @ApiOperation("删除体征参考")
    @DeleteMapping("/removeById")
    public R removeById(@RequestParam("referenceId") Integer referenceId){
        return new R<>(referenceService.removeById(referenceId));
    }

    /**
     * 查询全部
     * @param
     * @return R
     */
    @ApiOperation("查询全部")
    @GetMapping("/queryAll")
    public R queryAll(){
        return new R<>(referenceService.list());
    }


    @ApiOperation("按类型查询")
    @GetMapping("/queryByType")
    public R queryByType(Integer type){
        Reference reference = new Reference();
        reference.setType(type);
        return new R<>(referenceService.list(Wrappers.query(reference)));
    }

}
